package com.derbysoft.synxisadapter.action.monitor.reservation;

import com.derbysoft.core.LimitedList;
import com.derbysoft.synxisadapter.action.BaseAdapterAction;
import com.derbysoft.synxisadapter.commons.model.Reservation;
import com.derbysoft.synxisadapter.commons.repository.ReservationRepository;
import com.derbysoft.synxisadapter.commons.repository.impl.ReservationCondition;
import com.opensymphony.xwork2.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;


@Results(value = {
    @Result(name = Action.SUCCESS, location = "/page/monitor/reservation/Query.ftl")
})
public class QueryAction extends BaseAdapterAction {

    @Autowired
    private ReservationRepository reservationRepository;

    private ReservationCondition condition = new ReservationCondition();
    private LimitedList<Reservation> reservations = new LimitedList<Reservation>();

    public String query() throws Exception {
         reservations = reservationRepository.findByCondition(condition, createLimit());
         paging(reservations);
         return SUCCESS;
    }

    public ReservationCondition getCondition() {
        return condition;
    }

    public void setCondition(ReservationCondition condition) {
        this.condition = condition;
    }

    public LimitedList<Reservation> getReservations() {
        return reservations;
    }
}
